package com.tian.demo01.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/7/14/11:29
 */
@Configuration
public class GlobalConfig {

    /**
     *
     * 创建mp分页拦截器实例
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return mybatisPlusInterceptor;
    }

    /**
     *创建swagger实例
     * @return
     */
    @Bean
    public Docket docket() {
        Docket docket=
                new Docket(DocumentationType.SWAGGER_2)
                        .apiInfo(getInfo())//设置接口文档的信息
                        .select()
                        .apis(RequestHandlerSelectors.basePackage("com.tian.demo01.controller")) //指定为那些路径下得到类生成接口文档
                        .build()
                ;

        return docket;
    }

    /**
     * 配置接口文档信息
     * @return
     */
    private ApiInfo getInfo(){
        Contact DEFAULT_CONTACT = new Contact("tian", "http://www.tian.com", "110@qq.com");
        ApiInfo DEFAULT = new ApiInfo("用户管理系统API", "该系统中的接口专门操作用户的", "v1.0", "http://www.tian.com",
                DEFAULT_CONTACT, "礼悦莘恬", "http://www.tian.com", new ArrayList<VendorExtension>());
        return DEFAULT;
    }
}
